import Reqwest from '../../../utils/Reqwest';
import {AdAppDisplayDTO} from './AdAppDisplayDTO';
import {AdAppPageDisplayDTO} from './AdAppPageDisplayDTO';
import {AdAppPagePositionDisplayDTO} from './AdAppPagePositionDisplayDTO';
import {AdAppPlatformDisplayDTO} from './AdAppPlatformDisplayDTO';
import {base, assign, redirect}  from '../../base/Base';
import {ResponseDto} from '../../base/BaseDTO';

declare let GLOBAL:any;

export class AdAppPositionController {
    path = `${GLOBAL.baseApiUrl}/adPartner/api`;

    
    /**
     * 获取所有的业务方内容
     * 
     * @param {{
     *         partnerId?:number
     *     }} params 
     * @param {any} [options={}] 
     * @returns {Promise<ResponseDto<any>>} 
     * 
     * @memberof AdAppPositionController
     */
    getAllbuList(params:{
        partnerId?:number
    },options={}):Promise<ResponseDto<any>>{
        return new Reqwest(assign({
            url: `${this.path}/allBUList.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }


    /**
     * 获取业务方内容
     * 
     * @param {{
     *         businessUnitId?:number
     *     }} params
     * @param {any} [options={}]
     * @returns {*}
     * 
     * @memberOf AdAppPositionController
     */
    getPartnerBu(params:{
        partnerId?:number
    },options={}):Promise<ResponseDto<any>>{
        return new Reqwest(assign({
            url: `${this.path}/BUList.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * 
     * 查询applist
     * @param {{
     *         partnerId?:number
     *     }} params
     * @param {any} [options={}]
     * @returns {*}
     */
    getPartnerApps(params:{
        BUId:number
    },options={}):Promise<ResponseDto<any>>{
        return new Reqwest(assign({
            url: `${this.path}/applist.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /** 
     * 根本局app查询平台 
     * @param {{
     *         partnerId?:number
     *     }} params
     * @param {any} [options={}]
     * @returns {*}
     * 
     * @memberOf AdController
     */
    getPartnerAppPlatforms(params:{
        BUId:number,
        appId:number
    },options={}):Promise<ResponseDto<any>>{
        return new Reqwest(assign({
            url: `${this.path}/appPlatforms.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * 根据app和平台查询页面 
     * @param {{
     *         partnerId?:number
     *     }} params
     * @param {any} [options={}]
     * @returns {*}
     * 
     * @memberOf AdController
     */
    getPartnerAppPages(params:{
        BUId:number,
        appId:number, 
        platform:number
    },options={}):Promise<ResponseDto<any>>{
        return new Reqwest(assign({
            url: `${this.path}/appPages.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    
    /**
     * 
     * 获取广告位信息
     * @param {{
     *         appId:number,
     *         platform:number,
     *         pageId:number
     *     }} params
     * @param {any} [options={}]
     * @returns {*}
     * 
     * @memberOf AdAppPositionController
     */
    getPartnerAppPagePositions(params:{
        BUId:number,
        appId:number,
        platform:number,
        pageId:number
    },options={}):Promise<ResponseDto<any>>{
        return new Reqwest(assign({
            url: `${this.path}/appPagePositions.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    
    /**
     * 获取广告类型
     * 
     * @param {{
     *         positionId:number
     *     }} params 
     * @param {any} [options={}] 
     * @returns {*} 
     * 
     * @memberOf AdAppPositionController
     */
    getMediaType(params:{
        position:number
    },options={}): Promise<ResponseDto<any>>{
        return new Reqwest(assign({
            url: `${this.path}/mediaTypes.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            data: params || {},
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }

    /**
     * 获取广告类型
     * 
     * @param {{
     *         positionId:number
     *     }} params 
     * @param {any} [options={}] 
     * @returns {*} 
     * 
     * @memberOf AdAppPositionController
     */
    getAllMediaType(options = {}): Promise<ResponseDto<any>>{
        return new Reqwest(assign({
            url: `${this.path}/types.jhtml`,
            method: 'get',
            type: 'json',
            contentType: 'application/json; charset=UTF-8',
            headers: {
                'X-CSRF-TOKEN': base._csrf
            }
        }, options)).catch(redirect);
    }
}

